package cn.com.klun.tjy.other.lambda;

import javax.jws.WebService;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.IntStream;

public class StreamsTest {


    public static String query(String question) {
        List<String> engines = new ArrayList<String>() {{
            add("http://www.google.com/?q=");
            add("http://duckduckgo.com/?q=");
            add("http://www.bing.com/search?q=");
        }};
        // get element as soon as it is available
        Optional<String> result = engines.stream().parallel().map((base) -> {
            String url = base + question;
            // open connection and fetch the result
            //return WS.url(url).get();
            return "";
        }).findAny();
        return result.get();
    }

    public static void getSomething() {
        long a = IntStream.range(0, 100).mapToLong(x -> {
            for (int i = 0; i < 1_0_00; i++) {
                System.out.println("X:" + i);
            }
            return x;
        }).sum();
    }

    public static void main(String[] args) {
        getSomething();
    }
}
